package com.bfly.mall.report.controller;

import com.alibaba.fastjson.JSONObject;
import com.bfly.common.ResponseUtil;
import com.bfly.common.util.DateUtil;
import com.bfly.core.base.controller.BaseController;
import com.bfly.core.base.entity.ResponseData;
import com.bfly.core.security.PermissionCheck;
import com.bfly.mall.product.enums.ProductCommentStatusEnum;
import com.bfly.mall.product.service.IProductCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 评论统计
 * @author 长沙商脉科技有限公司
 * @date 2020/10/16 20:46
 */
@RestController
@RequestMapping(value = "/manage/report")
public class CommentReportController extends BaseController {

    @Autowired
    private IProductCommentService commentService;

    /**
     * 评论综合统计
     *
     * @author 长沙商脉科技有限公司
     * @date 2020/6/4 11:35
     */
    @GetMapping(value = "/comment/statistics")
    @PermissionCheck(required = false)
    public void statisticsProduct(HttpServletResponse response) {
        Map<String, Object> param = new HashMap<>();

        // 总评论数
        param.put("is_poster", true);
        long comments = commentService.getCount(param);

        // 总待审核评论数
        param.put("status", ProductCommentStatusEnum.WAIT.getId());
        long waits = commentService.getCount(param);

        // 待回复评论数
        param.put("is_reply", false);
        long unReplys = commentService.getCount(param);

        // 今日评论数
        param.remove("reply");
        param.remove("status");

        Date beginDate = DateUtil.getCurrentDayMorning();
        Date endDate = DateUtil.getCurrentDayNight();
        param.put("create_date_beginDate", beginDate);
        param.put("create_date_endDate", endDate);

        long totadys = commentService.getCount(param);

        JSONObject json = new JSONObject();
        json.put("comment", comments);
        json.put("wait",waits);
        json.put("unReply", unReplys);
        json.put("today", totadys);
        ResponseUtil.writeJson(response, ResponseData.getSuccess(json));
    }
}
